package com.zrgk.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zrgk.bean.ConContentBean;
import com.zrgk.dao.ConContentDao;
import com.zrgk.util.PageUtil;


@Service(value = "conContentService")
@Transactional(propagation = Propagation.REQUIRED)
public class ConContentServiceImpl implements ConContentService {
	@Autowired
	@Qualifier("conContentDao")
	private ConContentDao conContentDao;

	public ConContentDao getConContentDao() {
		return conContentDao;
	}

	public void setConContentDao(ConContentDao conContentDao) {
		this.conContentDao = conContentDao;
	}
	
	public List<ConContentBean> listConContent() {
		
		return conContentDao.listConContent();
	}
	public void insertConContent(ConContentBean cocon) {
		
		conContentDao.insertConContent(cocon);		
	}

	public void updateConContent(ConContentBean cocon) {

        conContentDao.updateConContent(cocon);		
	}

	public void findConContentByPage(PageUtil pageUtil) {
		Page<ConContentBean> page = PageHelper.startPage(pageUtil.getNowPage(),pageUtil.getPageSize());
		List<ConContentBean> cocon = conContentDao.listConContent();
		for(ConContentBean c:cocon){
			System.out.println(c);
		}
		pageUtil.setList(cocon);
		pageUtil.setTotalCount((int)page.getTotal());
	    pageUtil.setTotalPage(page.getPages());
	}

	public ConContentBean findConContentById(int id) {
		
		return conContentDao.ConContentById(id);
	}

	public PageUtil findConContentByPage1(PageUtil pu) {
		Page<ConContentBean> page = PageHelper.startPage(pu.getNowPage(), pu.getPageSize());
		List<ConContentBean> list = conContentDao.queryByOrderPage(pu.getSearchInfo());
		pu.setList(list);
		Long total = page.getTotal();
		pu.setTotalCount(total.intValue());
		pu.setTotalPage(page.getPages());
		return pu;
	}

	public void updateContentState(ConContentBean cocon) {
		conContentDao.updateContentState(cocon);
		
	}
}
